import 'package:flutter/material.dart';

class GestureDetectorPage extends StatefulWidget {
  @override
  _GestureDetectorPageState createState() => _GestureDetectorPageState();
}

class _GestureDetectorPageState extends State<GestureDetectorPage> {
  String _gestureStatus = 'No Gesture';
  Offset _position = Offset.zero;
  double _scale = 1.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('GestureDetector Demo')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Gesture: $_gestureStatus'),
            SizedBox(height: 20),
            Text('Position: (${_position.dx.toStringAsFixed(1)}, ${_position.dy.toStringAsFixed(1)})'),
            SizedBox(height: 20),
            Text('Scale: ${_scale.toStringAsFixed(2)}'),
            SizedBox(height: 20),
            GestureDetector(
              //点击
              onTap: () {
                setState(() {
                  _gestureStatus = 'Tap';
                });
              },
              //双击
              onDoubleTap: () {
                setState(() {
                  _gestureStatus = 'Double Tap';
                });
              },
              //长按
              onLongPress: () {
                setState(() {
                  _gestureStatus = 'Long Press';
                });
              },
              onScaleUpdate: (details) {
                setState(() {
                  _gestureStatus = 'Scale';
                  _position = details.localFocalPoint;
                  _scale = details.scale;
                });
              },
              child: Container(
                width: 200,
                height: 200,
                color: Colors.blue.withOpacity(0.3),
                child: Center(
                  child: Text('Gesture Area'),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
